<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <script th:src="@{/layui/layui.js}"></script>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <script th:src="@{/layui/layui.all.js}"></script>
</head>
<body>
<div id="toolBar" style="display: none">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="dodel"><i class="layui-icon">&#xe640;</i>删除</button>
    </div>
</div>

<a th:href="@{/sys/fsobtiannowday}">
    <button class="layui-btn-primary layui-bg-red layui-btn-lg" >抓取今日焦点栏目新闻</button>
    <p style="color:red;" th:text="${success}" th:if="${not #strings.isEmpty(success)}"></p>
</a>

<table id="tabledemo" lay-filter="tabledemo"></table>


<script th:src="@{/layui/layui.all.js}"></script>
<script th:src="@{/layui/layui.js}"></script>
<script th:inline="none">
    layui.use(['table', 'layer','form'], function () {
        const table = layui.table,
            $=layui.$;
        table.render({
            elem: '#tabledemo',
            url: '/sys/fscusnewsjson',//返回一个focusnewsjson的JSON
            toolbar: '#toolBar',
            page: true
            , cols: [[
                {type: 'checkbox'}
                , {field: 'id', title: 'ID', width: 80, sort: true}
                , {field: 'title', title: '名称', width: 250, sort: true}
                , {field: 'titleImg', title: '新闻图片地址', width: 350}
                , {field: 'titleHref', title: '新闻地址', width: 350}
                , {field: 'gmtCreate', title: '插入时间', width: 200}
            ]]
        });

        table.on('toolbar(tabledemo)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            switch (obj.event) {
                case 'dodel':
                    var  lakerId = "";
                    if(data.length===0){
                        layui.msg("请选择要删除的数据");
                    }
                    if (data.length > 0) {
                        for (const i in data) {
                            lakerId += data[i].id+",";
                        }
                        layer.confirm('确定删除吗？', function (index) {
                            $.post({
                                url: '/sys/fscolumbatchbyid',
                                data: {"ids":lakerId},
                                success: function (msg) {
                                    if (msg === "OK") {
                                        table.reload('tabledemo');
                                        layer.msg('已删除');
                                    } else {
                                        layer.msg('删除失败');
                                    }
                                }
                            })
                            table.reload('tabledemo');

                        });
                    }

                    table.reload('tabledemo');
                    break;
            }

        })
    })
</script>
</body>
</html>